export function isSubObject(sub, sup) {
  return Object.keys(sub).every(value => sup.hasOwnProperty(value) && sup[value] === sub[value]);
}

export function deepClone(source) {
  if (!source || typeof source !== 'object') {
    throw new Error('error arguments', 'shallowClone');
  }
  var targetObj = source.constructor === Array ? [] : {};
  for (var keys in source) {
    if (source.hasOwnProperty(keys)) {
      if (source[keys] && typeof source[keys] === 'object') {
        targetObj[keys] = source[keys].constructor === Array ? [] : {};
        targetObj[keys] = deepClone(source[keys]);
      } else {
        targetObj[keys] = source[keys];
      }
    }
  }
  return targetObj;
}

export const delay = (function() {
  let timer = 0;
  return function(callback, ms = 500) {
    clearTimeout(timer);
    timer = setTimeout(callback, ms);
  };
})();
